/*
* @file bsp_i2s.h
* @brief I2S driver for ESP32
* @author feiniao
* @date 2023-10-01
* @version 1.0
*
* This file contains the definition of the BSP_I2S class, which provides an interface for I2S communication.
* The class allows reading audio data from an I2S microphone.
*/


#ifndef BSP_I2S_H
#define BSP_I2S_H

#include "driver/i2s.h"
#include "driver/gpio.h"
#include <cstdint>

#define Microphone_I2S_Port      I2S_NUM_0
#define loudspeaker_I2S_Port     I2S_NUM_1

class BSP_I2S
{
private:
    int                         bck_io_num;         /*!< BCK pin, input in slave role, output in master role */
    int                         ws_io_num;          /*!< WS pin, input in slave role, output in master role */
    int                         data_in_num;        /*!< DATA pin, input, for esp*/
    int                         data_out_num;       /*!< DATA pin, output, for esp*/
    uint32_t                    sample_rate;
    i2s_port_t                  i2s_port;
    i2s_mode_t                  i2s_mode;
    i2s_bits_per_sample_t       bits_per_sample;

public:
    BSP_I2S(int bck_io_num, int ws_io_num, int data_in_num, int data_out_num, uint32_t sample_rate, i2s_port_t i2s_port, i2s_mode_t i2s_mode, i2s_bits_per_sample_t i2s_bits_per_sample);
    ~BSP_I2S();

    int32_t int32t_read();

    int16_t int16t_read();

    esp_err_t write(const void* buffer, size_t bytes_to_write);
};


#endif